<?php
	/**
	 * thumb.class plugin for mime type: gif
	 * 
	 * @package Yomm
	 * @version 1.0
	 * @author bsuter
	 * 
	 * changelog:
	 * 2.0 [05.04.2011] prepared for Yomm Framework
	 * 1.0 [13.09.2010] first release of png plugin
	 */
	Class Yomm_Image_Plugin_Gif {
	
		/**
		 * resample method for jpeg thumb plugin
		 * 
		 * @param $size_arr 	[array] 	ex. array(0 => 66.3, 1 => 100)
		 * @param $image_arr 	[array] 	ex. array('source' => 'C:\php\flower.jpg', 'mime_type' => 'png')
		 * @param $file_name 	[char] 		ex. 'images/thumbs/125077576430928_thumb.png'
		 * @return boolean
		 */
		public static function resample($size_arr, $image_arr, $file_name)
		{
			list($tb_width, $tb_height) = $size_arr;
			
			list($or_width, $or_height) = getimagesize($image_arr['source']);
		
			if(($sh_img = @ImageCreateTrueColor($tb_width, $tb_height)) === false)
			{
				throw new Yomm_Error(__CLASS__ . ': Error while creating image shell for new thumb file!');
				return false;
			}
			
			if(@imagealphablending($sh_img, false) === false)
			{
				throw new Yomm_Error(__CLASS__ . ': Error while setting ImageAlphaBlending for png file');
				return false;
			}
			
 			
			if(($or_img = @ImageCreateFromGIF($image_arr['source'])) === false)
			{
				throw new Yomm_Error(__CLASS__ . ': Error while creating image stream from original!');
				return false;
			}
			
			if(@ImageCopyResampled($sh_img, $or_img, 0, 0, 0, 0, $tb_width, $tb_height, $or_width, $or_height) == false)
			{
				throw new Yomm_Error(__CLASS__ . ': Error while copy and resample from original to new!');
				return false;
			}
			
			if(@ImageGIF($sh_img, $file_name, 0) === false)
			{
				throw new Yomm_Error(__CLASS__ . ': Error while generating and saving image!');
				return false;
			}
			
			return true;
		}
	}
?>